﻿/*
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2022-10-25 15:55:42
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @LastEditTime: 2022-10-27 11:21:59
 * @FilePath: \WYW_0419_Oasis\JavaScripts\PlayerThings.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
@MWCore.MWClass
export default class PlayerThings extends MWCore.MWScript {

	@MWCore.MWProperty()
	player:GamePlay.Player

	/** 当脚本被实例后，会在第一帧更新前调用此函数 */
	protected async onStart(): Promise<void> {
		if(GamePlay.isClient())
		{
			let player=await GamePlay.asyncGetCurrentPlayer()

			let character=player.character

			//角色跳跃
			Events.addLocalListener("jump",()=>{
				character.jump()
			})

			//角色飞行
			Events.addLocalListener("fly",()=>{
				character.switchToFlying();
				character.brakingDecelerationFlying=500;
				character.maxFlySpeed=1000;
				setTimeout(()=>{
					character.switchToWalking();
				},7000)
			})

			//角色隐身
			Events.addLocalListener("stealth",()=>{
				character.onSkill1Trigger.add(()=>{
					character.isVisible=true;
					setTimeout(() => {
						character.onSkill2Trigger.add(()=>{
							character.isVisible=false;
						})
					}, 4000);
				})	
			})
		}
	}

	/** 
	 * 每帧被执行,与上一帧的延迟 dt 秒
	 * 此函数执行需要将this.bUseUpdate赋值为true
	 */
	protected onUpdate(dt: number): void {

	}

	/** 脚本被销毁时最后一帧执行完调用此函数 */
	protected onDestroy(): void {

	}

}
